package com.lh.io.bio.file;

import java.io.*;
import java.net.Socket;

public class Client {

    public static void main(String[] args) {

        try {
            File file = new File("C:\\Users\\17838330192\\Desktop\\test.txt");
            String fileName = file.getName();//test.txt
            String[] split = fileName.split("\\.");

           String suffix = split[1]; //txt
            FileInputStream is = new FileInputStream(file);

            Socket socket = new Socket("127.0.0.1", 8888);
            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());

            dos.writeUTF(suffix);

            int readLine = 0;
            byte[] buffer = new byte[1024];
            while ((readLine = is.read(buffer)) > 0){
                dos.write(buffer,0,readLine);
            }
            dos.flush();
            //通知服务端输出流已经发送完毕
            socket.shutdownOutput();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
